package org.noote.libs.widget;

import javax.microedition.khronos.opengles.GL10;

import android.content.Context;
import android.view.MotionEvent;

public class WidgetRenderer extends org.noote.libs.sogle.Renderer {

	public WidgetDekstop _dekstop = null;

	protected boolean _bDrawFPS = false;
	
    public WidgetRenderer(Context context)
    {
    	super(context);
    	
    	_dekstop = new WidgetDekstop(this);
    }
    
    public void drawFPS(boolean bEnable)
    {
    	_bDrawFPS = bEnable;
    }
    
    @Override
	public void onCreateScene(GL10 gl)
    {
    	super.onCreateScene(gl);
    	
		_dekstop.loadTheme(gl);
    }
    
	@Override
	public void onResize(int width, int height)
	{
		super.onResize(width, height);
		
		_dekstop.setWorkSpace(0, 0, width, height);
	}
	
	@Override
	public void onTouchEvent(final MotionEvent event)
	{
		_dekstop.touch(event, false);
	}
	
	@Override
	protected void _draw2D(GL10 gl, float fTimeSlice) {
		// draw 2D (after 3d rendering) like GUI
		
        set2DProjection(gl);
        gl.glDisable(GL10.GL_LIGHTING);
        gl.glClearDepthf(1.0f);
        gl.glMatrixMode(GL10.GL_MODELVIEW);
        gl.glLoadIdentity();
        
        _dekstop.draw(gl, 0);
        
        if(_bDrawFPS)
        {
	        _dekstop.getTheme().drawText(gl, _width/2, 20, String.format("FPS : %3.1f", _fps.getFPS()), true);
        }
	}
}
